﻿using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace NTmdb.TestProject
{
    /// <summary>
    ///     This is a test class for TmdCompanyPreviewListTest and is intended
    ///     to contain all TmdCompanyPreviewListTest Unit Tests
    /// </summary>
    [TestClass]
    public class TmdCompanyPreviewListTest
    {
        /// <summary>
        ///     A test for TmdCompanyPreviewList Constructor
        /// </summary>
        [TestMethod]
        public void TmdCompanyPreviewListConstructorTest()
        {
            var target = new TmdCompanyPreviewList();
            Assert.IsNotNull( target );
        }

        /// <summary>
        ///     A test for Companies
        /// </summary>
        [TestMethod]
        public void CompaniesTest()
        {
            var target = new TmdCompanyPreviewList();
            var expected = new List<TmdCompanyPreview>();
            target.Companies = expected;
            var actual = target.Companies;
            Assert.AreSame( expected, actual );
        }

        /// <summary>
        ///     A test for Serialize & Deserialize
        /// </summary>
        [TestMethod]
        [DeploymentItem(@"..\..\TestData\companyPreviewList.json.txt")]
        public async  Task SerializeDeserializeTest()
        {
            var target = new TmdCompanyPreviewList();
            var jsonContent = File.ReadAllText("companyPreviewList.json.txt");
            var actual = await target.DeserializeJson<TmdCompanyPreviewList>(jsonContent);

            Assert.AreEqual( 1, actual.PageNumber );
            Assert.AreEqual(39, actual.TotalResults);
            Assert.AreEqual(2, actual.TotalPages);
            Assert.AreEqual( 3, actual.Companies.Count );

            Assert.AreEqual( 5100, actual.Companies[0].Id );
            Assert.AreEqual(null, actual.Companies[0].LogoPath);
            Assert.AreEqual("Mammoth Screen", actual.Companies[0].Name);

            Assert.AreEqual(2690, actual.Companies[1].Id);
            Assert.AreEqual("/das1dad21easdasdas.jpg", actual.Companies[1].LogoPath);
            Assert.AreEqual("Screen Yorkshire", actual.Companies[1].Name);

            Assert.AreEqual(4222, actual.Companies[2].Id);
            Assert.AreEqual(null, actual.Companies[2].LogoPath);
            Assert.AreEqual("Screen Guild Productions", actual.Companies[2].Name);
        }
    }
}